const orderModel = require('../model/orderModel');


//获取d订单数据
module.exports.find = async function (page, searchParams) {
    let { current, pageSize } = page;
    // 根据查询条件获取总数
    let total = await orderModel.countDocuments(searchParams);
    // 根据查询条件获取具体数量的数据
    let data = await orderModel.find(searchParams)
        .populate({ path: "userId" })
        .limit(pageSize)
        .skip((current - 1) * pageSize)
        ;
    return {
        current, pageSize, total, data
    }
}


// id查找
module.exports.findById = async function (id) {
    return await orderModel.findById(id);
}

// 添加
module.exports.insert = async function (order) {
    return await orderModel.create(order);
}

// 删除
module.exports.delete = async function (id) {
    return await orderModel.deleteOne({ _id: id });
}
// 修改
module.exports.update = async function (order) {
    return await orderModel.updateOne({ _id: order._id }, order);
}


module.exports.findAll = async function () {
    return await orderModel.find();
}